package src.main.StructuralPatterns.Proxy.Static;

public class FileAccessProxy implements FileAccess{
    private final FileAccess fileAccess;
    private final String userRole;

    public FileAccessProxy(String userRole) {
        this.fileAccess = new RealFileAccess();
        this.userRole = userRole;
    }

    @Override
    public void readFile(String fileName) {
        fileAccess.readFile(fileName); // 所有用户均可读
    }

    @Override
    public void writeFile(String fileName) {
        if ("admin".equals(userRole)) { // admin可写
            fileAccess.writeFile(fileName);
        } else {
            System.out.println("refused to write file");
        }
    }
}
